//package edu.whut.mall.admin.service.impl;
///**
// * Author: smq
// * Unit: D9lab
// * Date: 2021-06-26 17.40
// */
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import edu.whut.mall.common.mybatis.ParamsMap;
//import edu.whut.mall.common.util.FileUtil;
//import edu.whut.mall.common.vo.Page;
//import edu.whut.mall.common.enums.FileType;
//import edu.whut.mall.pojo.mapper.FileMapper;
//import edu.whut.mall.pojo.model.File;
//import edu.whut.mall.common.vo.FileVo;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import org.springframework.validation.annotation.Validated;
//
//import javax.annotation.Resource;
//import javax.validation.constraints.NotNull;
//import java.util.Date;
//import java.util.List;
//
//@Service
//@Slf4j
//@Validated
//public class FileManageServiceImpl implements IFileManageUserService {
//
//    @Resource
//    private FileMapper fileMapper;
//
////    @Autowired
////    private ApkMapper apkMapper;
//
//    @Override
//    public FileVo getOneFile(int id){
//        return fileMapper.getFile(id);
//    }
//
//    @Override
//    public Page<FileVo> getFilePage(int current, int size, String orderBy, Boolean asc,
//                                    Integer id, String url, Integer isDeleted) throws Exception {
//        //分页查询参数构造(其它业务分页查询与此类似,改变的最多是查询参数构造)
//        ParamsMap hashMap = ParamsMap.getPageInstance(current, size, orderBy, asc);
//        hashMap.put("id", id);
//        hashMap.put("url", url);
//        hashMap.put("isDeleted", isDeleted);
//        //开始查询记录和数量
//        List<FileVo> list = fileMapper.getFilePage(hashMap);
//        Integer count = fileMapper.findCountFilePage(hashMap);
//        Page<FileVo> page = new Page<>(list, count, current, size);
//        return page;
//    }
//
//    @Override
//    public Integer deleteFile(int id) throws Exception {
//        return fileMapper.deleteFile(id);
//    }
//
////    @Override
////    public String queryLatestApk() throws Exception {
////        String latestApk = apkMapper.getApkFile();
////        return latestApk;
////    }
//
////    @Override
////    public Integer addOneAndroidApk(String version, File apk, String description) throws Exception {
////        HashMap<String, Object> hashMap = new HashMap<>();
////        hashMap.put("version", version);
////        hashMap.put("fileId", apk.getId());
////        hashMap.put("fileUrl", apk.getUrl());
////        hashMap.put("createTime", new Date());
////        hashMap.put("description", description);
////        return apkMapper.addOneApk(hashMap);
////    }
//
////    @Override
////    public ApkFileVO getLatestApk() throws Exception {
////        return apkMapper.getLatestApk();
////    }
//
//    @Override
//    public File addOneFile(@NotNull(message = "url不能为null") String url) {
//        return addOneFile(url,FileType.图片);
//    }
//
//    @Override
//    public File addOneFile(@NotNull(message = "url不能为null")String url, FileType fileType) {
//        QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>();
//        fileQueryWrapper.eq("url",url);
//        File tempFile = fileMapper.selectOne(fileQueryWrapper);
//        if (tempFile !=null){
//            return tempFile;
//        }
//        File file = new File(url, new Date(), false, fileType);
//        fileMapper.insert(file);
//        return file;
//    }
//
//    @Override
//    public void deleteFiles() throws Exception {
//        //每次获取100条未被删除的记录
//        Page<FileVo> page = getFilePage(1, 100, "create_time", false, null, null, 0);
//        List<FileVo> list = page.getList();
//        for(int i=0; i<page.getList().size(); i++){
//            int id = list.get(i).getId();//文件记录id
//            String url = list.get(i).getUrl();//文件记录id
//            log.info("文件id:"+id+"   url:"+url);
//            deleteFile(id);
//            //删除fastdfs的文件
//            if (null != url){
//                FileUtil.delete(url);//删除文件
//            }
//        }
//    }
//
//
//}
